package com.epcs.controller.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.epcs.model.bo.FollowingBO;
import com.epcs.model.bo.UserBO;
import com.epcs.model.dto.Account;
import com.opensymphony.xwork2.Action;

public class InvitedPeopleAction implements SessionAware{

	private String[] json;
	private String term;
	private String eventId;
	private SessionMap<String, Object> sessionMap;
	
	public String getInvitedPeopleJson() {

		UserBO userBO = new UserBO();
		FollowingBO followingBO = new FollowingBO();
		Account currentUser = (Account) sessionMap.get("USER_INFO");
		
		List<Account> accountList = new ArrayList<Account>();
		accountList.add(currentUser);
		
		if (eventId != null){
			// tức là lấy list các account cho việc mời thêm
			accountList.addAll(followingBO.getAllAccountFollowEvent(Integer.parseInt(eventId)));
		}
		
		// trừ những người đã có trong list
		json = userBO.searchUser(term, accountList);
		return Action.SUCCESS;
	}

	public String getTerm() {
		return term;
	}

	public void setTerm(String term) {
		this.term = term;
	}

	public String[] getJson() {
		return json;
	}

	public void setJson(String[] json) {
		this.json = json;
	}

	public String getEventId() {
		return eventId;
	}

	public void setEventId(String eventId) {
		this.eventId = eventId;
	}
	
	// ---------------- session --------------------//
	@Override
	public void setSession(Map<String, Object> sessionMap) {
		this.sessionMap = (SessionMap<String, Object>) sessionMap;
	}
	
}
